<?php

namespace app\controller;
use app\model\information;
use app\model\user;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;
use app\model\department;
use think\facade\View;

class Departmentr extends BaseController
{
public function index(){
    $d=new Department();
    $key=Request::param('key');
    if(!empty($key)){
        $data=$d->search();
    }else{
        $data=$d->paginate(5);
    }
    View::assign(['data'=>$data]);
    return View::fetch();
}
    function update(){
        $data=Request::post();
        $d=new department();
        $res=$d->where('num',$data['num'])->update($data);
//        $res=Db::table('doctor')->update($data);
        if($res){
            return 1;
        }else{
            return 0;
        }
//        return ($res);
    }
    function edit(){
        $id=Request::get('id');
        $d=new department();
//        $data=$d->find($id);
        $data=$d->where('num',$id)->find();
        return json($data);
    }
    public function del(){
        $id=Request::param('id');
        $d=new department();
        $res=$d->where('num',$id)->delete();
        if($res){
            return 1;
        }else{
            return 0;
        }
    }
    public function insert(){
        $p=Request::post();
        $d=new department();
        $res=$d->insert($p);
//        $res=Db::table('subjecttype')->insert($p);
        if($res){
            return 1;
        }else{
            return 0;
        }

    }
}